# -*- coding: utf-8 -*-
'''
模块：生意通-经营数据-经营概况
输入：cookie,hotel_id,hotel_name
输出：single_day_sales # 单日销售额
      night_number     # 夜间量
'''
import requests
import datetime
import json
import re
from fcs import url_request

def main(cookies,hotel_id,hotel_name):
    item={}
    today=datetime.datetime.now().strftime("%Y-%m-%d")
    url="http://syt.ctrip.com/api/dataCenter/sale/queryMarketDetails?hostType=Ebooking"
    header={
        'Content-Type':'application/json'
    }

    data={
        'platform':'0',
        'startDate':today,
        'startDateType':'0',
        'type':0
    }


    # con=requests.post(url=url,data=json.dumps(data),cookies=cookies,headers=header).text

    while True:
        try:
            con=url_request.post_url_requests(url=url,cookies=cookies,headers=header,data=json.dumps(data))
            json_data = json.loads(con)
            break
        except:
            continue

    c=re.compile('"tip1":(.*?),',re.S)
    tips=re.findall(c,con)
    try:
        single_day_sales=tips[0]
        night_number=tips[1]
    except:
        single_day_sales=''
        night_number=''
    item.update(single_day_sales=single_day_sales)
    item.update(night_number=night_number)
    return item
